<?php
	
	$iniVars = parse_ini_file('../config.ini',TRUE);
	include('../function/function.php');
	include('../classes/adodb5/adodb.inc.php');
	include('../function/db.func.php');
	
	$sql = "SELECT td_value FROM text_data WHERE td_id=35";
	$result = $db->Execute($sql);
	
	//echo $result->fields['td_value'];
	
	$name = ($_POST['name']);
	$email = $_POST['email']; 
	$contact_tel = $_POST['tel'];
	$comments = ($_POST['msg']); 

	$html_mail =  '<strong>ชื่อ : </strong>'.$name;
	$html_mail .=  '<br /><strong>อีเมล์ : </strong>'.$email;
	$html_mail .=  '<br /><strong>เบอร์โทร : </strong>'.$contact_tel;
	$html_mail .=  '<br /><strong>ข้อความ : </strong><br />'.$comments;
	
	$to      = $iniVars['Etc_Data']['contact_email'].','.$_POST['toemail'].','.trim($result->fields['td_value']);
	
	$subject = 'Message from feedback form';
	$message = $html_mail;

	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
	$headers .= "From: $email" . "\r\n" .
		"Reply-To: $email" . "\r\n" .
		'X-Mailer: PHP/' . phpversion();

	$result = @mail($to, $subject, $message, $headers);
	
	if($result)
	{
		echo <<<js
		<script>
			alert('เราได้รับข้อความของท่านแล้ว');
			window.location='../feedback.php';
		</script>
js;
	}
	else
	{
		echo <<<js
		<script>
			alert('ไม่สามารถส่งข้อความได้ กรุณาลองใหม่อีกครั้ง');
			window.location='../feedback.php';
		</script>
js;
	}
?>